/*
 * @Author: 田鑫
 * @Date: 2023-02-21 15:05:52
 * @LastEditors: 田鑫
 * @LastEditTime: 2023-02-21 15:08:07
 * @Description:
 */
/**
 * 11位有效电话号码验证规则
 */
const validPhoneNumber = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;

/**
 * 手机号验证
 */
export function validateMobile(value, callback) {
  if (value == '' || value == undefined) {
    callback();
  } else {
    // const reg = /^1([38]\d|5[0-35-9]|7[3678])\d{8}$/
    const reg = /^(13[0-9]|14[01456879]|15[0-3,5-9]|16[2567]|17[0-8]|18[0-9]|19[0-3,5-9])\d{8}$/;
    if (!reg.test(value)) {
      callback(new Error('不是有效的手机号'));
    } else {
      callback();
    }
  }
}

/**
 * 邮箱校验
 */
export function validateEmail(value, callback) {
  if (value == '' || value == undefined) {
    callback();
  } else {
    const reg = /^([0-9a-zA-Z_.-]+[@][0-9a-zA-Z_.-]+([.][a-zA-Z]+){1,2})+$/;
    if (!reg.test(value)) {
      callback(new Error('邮箱格式不正确'));
    } else {
      callback();
    }
  }
}

export const uuid = '1234';

export { validPhoneNumber };
